package com.xiaoliuzhi.android.uinput;

import java.io.DataOutputStream;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		upgradeRootPermission(getPackageCodePath());
	}
	
	
	/**
	 * 应用程序运行命令获取 Root权限，设备必须已破解(获得ROOT权限)
	 * 
	 * @return 应用程序是/否获取Root权限
	 */
	public boolean upgradeRootPermission(String pkgCodePath) {
		Process process = null;
		DataOutputStream os = null;
		try {
			String cmd = "chmod 777 " + pkgCodePath;
			String uiputcmd = "chmod 777 /dev/uinput";
			process = Runtime.getRuntime().exec("su");// 切换到root帐号
			os = new DataOutputStream(process.getOutputStream());

			os.writeBytes(cmd + "\n");
			os.writeBytes(uiputcmd + "\n");
			os.writeBytes("exit\n");
			os.flush();
			 process.waitFor();

		} catch (Exception e) {
			return false;
		}

		return true;
	}
}
